/*
1376.通知所有员工所需的时间 
https://leetcode.cn/problems/time-needed-to-inform-all-employees/description/
中等 2024/11/10
*/

class Solution {
public:
unordered_map<int,vector<int>>mp;
int dfs(int k,vector<int>& informTime)
{
    int ans=0;
    for(int i=0;i<mp[k].size();i++)
    {
        ans=max(ans,dfs(mp[k][i],informTime));
    }
    return ans+informTime[k];
}
    int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {
        for(int i=0;i<n;i++)
            mp[manager[i]].push_back(i);
        return dfs(headID,informTime);   
    }
};